<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #allmap {
      height: 100vh;
    }
  </style>
  <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=LTcdtaUhvwYYnvWd90tfvhBYBGgxmwbC"></script>
</head>

<body>
  <div id="allmap"></div>
  <script>
    // 思考题：能否精简到只需要获取 ip 地址，不需要看到地图？
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(116.331398, 39.897445);
    map.centerAndZoom(point, 12);

    function myFun(result) {
      var cityName = result.name;
      map.setCenter(cityName);
      alert("当前定位城市:" + cityName);
    }
    var myCity = new BMap.LocalCity();
    myCity.get(myFun); 
  </script>
</body>

</html>